package org.grottarossa.tms.ui.console.psapv;

import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.tms.aeroflow.ui.core.viewmanager.IViewManager;
import org.grottarossa.tms.aeroflow.ui.core.viewmanager.ModalPopupViewManager;
import org.grottarossa.tms.ui.console.ConsolePresenter;
import org.grottarossa.tms.ui.console.ConsoleView;
import org.grottarossa.tms.ui.console.DetailViewManager;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

/**
 * <p>Implementazione di {@link ConsoleView} in grado di visualizzare un'area menu, un'area dettaglio e popup modali.</p>
 *
 * @author 
 */
public class PSAConsoleView extends ConsoleView
{
	private static final long serialVersionUID = -5082365962275377439L;

	private IViewManager m_viewManager;
	private IViewManager m_viewManagerCase;

	//Barra laterale e body
	private VerticalLayout m_menusContainer;
	private VerticalLayout m_mainContent;

	public PSAConsoleView() throws DriverException
	{
		super();
	}

	@Override
	protected void initializeComponents()
	{
		getLayout().setHeight(100, Sizeable.UNITS_PERCENTAGE);
		getLayout().setWidth(100, Sizeable.UNITS_PERCENTAGE);

		m_menusContainer = new VerticalLayout();

		m_mainContent = new VerticalLayout();
		m_mainContent.addComponent(new Label("Selezionare un processo o una query"));

		m_mainContent.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		m_mainContent.setWidth(100, Sizeable.UNITS_PERCENTAGE);

		m_viewManager = new DetailViewManager(m_mainContent);
		m_viewManagerCase = new ModalPopupViewManager(m_mainContent, m_mainContent);

		addComponent(
				getHorizontalSplitPanel(
						m_menusContainer,
						m_mainContent
				)
		);
	}


	/**
	 * Visualizza un componente nell'area di dettaglio
	 * @param component
	 */
	@Override
	public void showInDetailArea(Component component)
	{
		m_viewManager.enterView(component);
	}

	/**
	 * Visualizza un componente utilizzando un popup modale
	 * @param component
	 */
	public Window showInPopup(Component component)
	{
		return m_viewManagerCase.enterView(component);
	}

	public void closePopup(Component component)
	{
		m_viewManagerCase.exitView(component);
	}

	/**
	 * <p>Imposta i componenti da visualizzare nell'area men�.</p>
	 * <p>I componenti precedentemente visualizzati vengono rimossi.</p>
	 * @param menus componenti da visualizzare nell'area men�
	 */
	public void setMenus(Component... menus)
	{
		m_menusContainer.removeAllComponents();

		for(Component menu: menus)
		{
			m_menusContainer.addComponent(menu);
		}
	}


}
